#include "apue.h"

int main(int argc, char *argv[]) {
    int    i;
    struct stat buf;
    char   *ptr;

    if (argc != 2) {
	    fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
	    exit(EXIT_FAILURE);
	}
    for (i = 1; i < argc; ++i) {
        printf("%s: ", argv[i]);
        if (lstat(argv[i], &buf) < 0) {
            err_ret("lstat error");
            continue;
        }
        if (S_ISREG(buf.st_mode))
            ptr = "普通文件\n";
        else if (S_ISDIR(buf.st_mode))
            ptr = "目录文件\n";
        else if (S_ISCHR(buf.st_mode))
            ptr = "字符特殊文件\n";
        else if (S_ISBLK(buf.st_mode))
            ptr = "块特殊文件\n";
        else if (S_ISFIFO(buf.st_mode))
            ptr = "管道\n";
        else if (S_ISLNK(buf.st_mode))
            ptr = "符号链接\n";
        else if (S_ISSOCK(buf.st_mode))
            ptr = "套接字\n";
        else
            ptr = "unknown mode";
        printf("%s\n", ptr);
    }
    return 0;
}